package com.jzo2o.customer.controller.consumer;

import com.jzo2o.common.model.PageResult;
import com.jzo2o.customer.model.domain.AddressBook;
import com.jzo2o.customer.model.dto.request.AddressBookPageQueryReqDTO;
import com.jzo2o.customer.model.dto.request.AddressBookUpsertReqDTO;
import com.jzo2o.customer.service.IAddressBookService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;

@Api("用户端-我的地址簿相关接口")
@RestController("UserAddressBookController")
@RequestMapping("/consumer/address-book")
public class AddressBookController {

    @Resource
    private IAddressBookService addressBookService;

    @PostMapping
    @ApiOperation("新增地址簿")
    public void add(@RequestBody AddressBookUpsertReqDTO dto){
        addressBookService.add(dto);
    }

    @GetMapping("/page")
    @ApiOperation("地址薄分页查询")
    public PageResult<AddressBook> page(AddressBookPageQueryReqDTO addressBookPageQueryReqDTO){
        return addressBookService.pageAddressBook(addressBookPageQueryReqDTO);
    }

    @GetMapping("/{id}")
    @ApiOperation("地址薄详情")
    public AddressBook getById(@PathVariable("id") Long id){
        return addressBookService.getById(id);
    }

    @PutMapping("/{id}")
    @ApiOperation("根据id修改地址簿")
    public void update(@PathVariable("id") Long id,@RequestBody AddressBookUpsertReqDTO dto){
        addressBookService.updateAddressBook(id,dto);
    }

    @DeleteMapping("/batch")
    @ApiOperation("批量删除地址簿")
    public void deleteBatch(@RequestBody ArrayList<String> ids) {
        addressBookService.deleteBatch(ids);
    }

    @PutMapping("/default")
    @ApiOperation("设置默认地址")
    public void defaultAddress(@RequestParam("id") Long id, @RequestParam("flag") Integer flag) {

        addressBookService.updateDefaultAddress(id, flag);
    }

    @GetMapping("/defaultAddress")
    @ApiOperation("获取默认地址")
    public AddressBook getDefaultAddress() {
        return addressBookService.getDefaultAddress();
    }
}
